#include "at24c02.h"
#include "i2c.h"

enum Address {
  at24c02 = 0xA0,
};

void at24c02_write(u8 address, u8 data) {
  i2c_start();
  i2c_write(at24c02);
  i2c_read_ack();
  i2c_write(address);
  i2c_read_ack();
  i2c_write(data);
  i2c_read_ack();
  i2c_stop();
}

u8 at24c02_read(u8 address) {
  u8 data;
  i2c_start();
  i2c_write(at24c02);
  i2c_read_ack();
  i2c_write(address);
  i2c_read_ack();
  i2c_start();
  i2c_write(at24c02 | 0b00000001);
  i2c_read_ack();
  data = i2c_read();
  i2c_write_ack(true);
  i2c_stop();
  return data;
}
